package com.fifth.home.controller;

import com.fifth.common.pojo.dto.CommonResult;
import com.fifth.common.pojo.entity.BottomArticle;
import com.fifth.common.pojo.entity.Link;
import com.fifth.home.service.ILinkService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 第五组
 * @since 2022-09-01
 */
@RestController
@RequestMapping("/home/link")
public class LinkController {
    @Autowired
    private ILinkService linkService;

    /**
     * 后台模糊查查询友情链接
     */
    @ApiOperation(value = "后台友情链接模糊查询接口")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "currentPage", value = "当前页码", dataType = "int"),
                    @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int"),
                    @ApiImplicitParam(name = "link", value = "友情链接实体类", dataType = "Link")
            }
    )
    @PostMapping("getAllLink/{currentPage}/{pageSize}")
    public CommonResult getAllLink(@PathVariable Integer currentPage, @PathVariable Integer pageSize, @RequestBody Link link){
        return linkService.selectAllLink(currentPage,pageSize,link);
    }

    /**
     * 后台添加友情链接
     */
    @ApiOperation(value = "后台友情链接添加接口")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "link", value = "友情链接实体类", dataType = "Link")
            }
    )
    @PostMapping("addLink")
    public CommonResult addLink( @RequestBody Link link){
        return linkService.insertLink(link);
    }

    /**
     * 修改友情链接状态
     *
     * @param linkId
     * @param isDisable
     * @return
     */
    @ApiOperation("友情链接修改状态接口")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "linkId", value = "友情链接id属性", dataType = "String"),
                    @ApiImplicitParam(name = "isDisable", value = "友情链接状态 0正常 1禁用", dataType = "String")
            }
    )
    @PostMapping("changeStatus/{linkId}/{isDisable}")
    public CommonResult updateDisable(@PathVariable String linkId, @PathVariable String isDisable) {
        return linkService.updateStatus(linkId, isDisable);
    }


    /**
     * 删除友情链接 逻辑删除
     *
     * @param linkId
     * @return
     */
    @ApiOperation(value = "友情链接删除接口")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "linkId", value = "linkId属性", dataType = "String")
            }
    )
    @PostMapping("deleteLink/{linkId}")
    public CommonResult deleteLink(@PathVariable String linkId) {
        return linkService.removeLink(linkId);
    }

    /**
     * 修改友情链接
     *
     * @param link
     * @return
     */
    @ApiOperation(value = "友情链接修改接口")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "link", value = "友情链接实体类", dataType = "Link")
            }
    )
    @PostMapping("editLink")
    public CommonResult editBottomArticle(@RequestBody Link link){
        return linkService.updateLink(link);
    }

    /**
     * 查看所有友情链接(前端调用)
     */
    @ApiOperation(value = "友情链接查询接口(前端调用)")
    @GetMapping("getQianLink")
    public CommonResult getQianLink(){
        return linkService.selectQianAllLink();
    }
}
